package com.toocms.jinjuhang.ui.mine.national_agency

import android.Manifest
import android.app.Application
import com.amap.api.location.AMapLocation
import com.amap.api.maps.model.LatLng
import com.blankj.utilcode.util.PermissionUtils
import com.toocms.tab.base.BaseModel
import com.toocms.tab.base.BaseViewModel
import com.toocms.tab.bus.event.SingleLiveEvent
import com.toocms.tab.map.TabMapApi
import com.toocms.tab.map.location.listener.LocationListener

class NationalAgencyModel(application: Application) : BaseViewModel<BaseModel>(application) {
    var locationChanged: SingleLiveEvent<LatLng> = SingleLiveEvent()

    fun requestPermissions() {
        PermissionUtils.permission(
            Manifest.permission.ACCESS_COARSE_LOCATION,
            Manifest.permission.ACCESS_FINE_LOCATION
        ).callback(object : PermissionUtils.SimpleCallback {
            override fun onGranted() {
                TabMapApi.getLocationApi().start(object : LocationListener {
                    override fun onLocationSuccess(aMapLocation: AMapLocation) {
                        val curLatlng = LatLng(aMapLocation.latitude, aMapLocation.longitude)
                        locationChanged.setValue(curLatlng)
                    }

                    override fun onLocationFail() {
                    }
                })
            }

            override fun onDenied() {
            }
        }).request()
    }
}


